package com.neuedu.controller;

import com.alibaba.fastjson2.JSON;
import com.neuedu.model.User;
import com.neuedu.service.UserService;
import com.neuedu.service.impl.UserServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController

public class UserController {
    @Autowired
    private UserServiceImpl userService;
    private static final Logger log = LoggerFactory.getLogger(UserController.class);

    @RequestMapping("/user/{uid}")

    public User queryUserById(@PathVariable("uid") Integer uid) throws InterruptedException{
        log.info("查询{}用户信息", uid);
        //因模拟需要，需要耗时60ms
        if (uid == 1){
            Thread.sleep(60);
        }
        //模拟异常
        if (uid ==2){
            throw new RuntimeException("查询用户信息失败");
        }
        User user = userService.queryUserById(uid);
        log.info("用户信息查询成功，内容为：{}", JSON.toJSONString(user));
        return user;
    }
}
